"""
@author: 江同学呀
@file: point_field.py
@date: 2024/7/28 19:46
@desc:
    https://www.elastic.co/guide/en/elasticsearch/reference/7.17/point.html

    Arbitrary cartesian points.
    任意笛卡尔点。
"""
from abc import ABC
from typing import Type, Union, Dict

from espc.orm.model.base.base import _Base
from espc.orm.model.struct.geo import PointType
from espc.orm.model.mapping.field.base_field.base_field import _BaseField
from espc.orm.model.mapping.field.field_attribute import IgnoreZValueAttribute, IgnoreMalformedAttribute, \
    NullValueAttribute
from espc.utils.build_add_attr import build_add_attr


class PointField(_BaseField, IgnoreMalformedAttribute, IgnoreZValueAttribute, NullValueAttribute, ABC):
    """
    点 字段
    """
    _field_type: str = "point"

    def __init__(
            self, field_name: str = None, value: PointType = None, default: str = None, ignore_malformed: bool = None,
            ignore_z_value: bool = None
    ):
        super(PointField, self).__init__(
            field_name=field_name, value=value, default=default, ignore_malformed=ignore_malformed,
            ignore_z_value=ignore_z_value
        )
        return

    def __get__(self, instance: _Base, owner: Type["PointField"]) -> Union["PointField", PointType]:
        return super(PointField, self).__get__(instance=instance, owner=owner)

    def __set__(self, instance, value: PointType):
        super(PointField, self).__set__(instance=instance, value=value)
        return

    def __getattribute__(self, item):
        return super(PointField, self).__getattribute__(item)

    @build_add_attr
    def _build(self) -> Dict:
        mapping: Dict = {
            "type": self._field_type
        }
        return mapping

